//
//  StatusForwardCell.swift
//  HMWeibo08
//
//  Created by 唐万超 on 15/8/5.
//  Copyright © 2015年 唐万超. All rights reserved.
//

import UIKit

class StatusForwardCell: StatusCell {
    
    
    // 重写父类属性
    override var statuses: Status? {
        didSet {
        
            // 设置转发微博的文字
            let name = statuses?.retweeted_status?.user?.name ?? ""
            let text = statuses?.retweeted_status?.text ?? ""
            forwardLabel.text = "@" + name + ": " + text
            
        }
    }

   
    //重写父类方法布局UI
    override func setUpUI() {
        
        // 记住一定要调用父类的布局UI方法
        super.setUpUI()
        
        // 添加控件
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(forwardLabel, aboveSubview: backButton)
        
        // 设置约束
        backButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -statusCellControlMargin, y: statusCellControlMargin))
        backButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        // 转发文本约束
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: backButton, size: nil, offset: CGPoint(x: statusCellControlMargin, y: statusCellControlMargin))
        
        // 配图约束
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: statusCellControlMargin))
        pictureWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        pictureHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
        pictureTopCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Top)
        
    }
    
    // MARK: - 懒加载控件
    // 文本
    private lazy var forwardLabel: UILabel = {
    
        let label = UILabel(color: UIColor.darkGrayColor(), fontSize: 14)
        
        // 设置换行与折行
        label.numberOfLines = 0
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * statusCellControlMargin
        
        return label
    }()
    // 背景按钮
    private lazy var backButton: UIButton = {
    
        let btn = UIButton()
        
        btn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        
        return btn
        
    }()
    

}
